import pymysql
import json

with open('xiaoshuo.json', 'r', encoding='utf-8') as file:
    data = json.load(file)

db = pymysql.connect(host='localhost', user='root', password='123456', database='film')

cursor = db.cursor()
for i in data["result"]["bookList"]:
    bookName = i["bookName"]
    authorName = i["authorName"]
    updateTime = i["updateTime"]
    totalWords = i["totalWords"]
    sql = "INSERT INTO xiaoshuo (`bookname`,`authorname`,`updatetime`,`totalwords`) values('%s','%s','%s','%s')" % (
    bookName, authorName, updateTime, totalWords)
    print(sql)
    cursor.execute(sql)
db.commit()
db.close()